package servlet.user;

import service.user.UserService;
import service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ChangPwd extends HttpServlet {
    private static final long serialVersionUID = 1L;
    UserService userService = new UserServiceImpl();
    public ChangPwd() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        int user_id = Integer.parseInt(request.getParameter("Userid"));
        String pw = request.getParameter("newPwd");
        String msg = null;
        int i = userService.updatePassword(user_id,pw);
        if (i>0) {

                response.sendRedirect(request.getContextPath() + "/page/user/changePwd.jsp?msg=1");
            } else {
                response.sendRedirect(request.getContextPath() + "/page/user/changePwd.jsp?msg=0");
            }
        }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
